<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="generator" content="hevea 2.18">
<link rel="stylesheet" type="text/css" href="manual.css">
<title>7.7&#XA0;&#XA0;Expressions</title>
</head>
<body>
<a href="patterns.html"><img src="previous_motif.gif" alt="Previous"></a>
<a href="language.html"><img src="contents_motif.gif" alt="Up"></a>
<a href="typedecl.html"><img src="next_motif.gif" alt="Next"></a>
<hr>
<h2 class="section" id="s:value-expr">7.7&#XA0;&#XA0;Expressions</h2>
<ul>
<li><a href="expr.html#sec128">7.7.1&#XA0;&#XA0;Basic expressions</a>
</li><li><a href="expr.html#sec137">7.7.2&#XA0;&#XA0;Control structures</a>
</li><li><a href="expr.html#sec144">7.7.3&#XA0;&#XA0;Operations on data structures</a>
</li><li><a href="expr.html#sec151">7.7.4&#XA0;&#XA0;Operators</a>
</li><li><a href="expr.html#sec152">7.7.5&#XA0;&#XA0;Objects</a>
</li><li><a href="expr.html#sec158">7.7.6&#XA0;&#XA0;Coercions</a>
</li><li><a href="expr.html#sec162">7.7.7&#XA0;&#XA0;Other</a>
</li></ul>
<p>
<a id="hevea_manual.kwd18"></a>
<a id="hevea_manual.kwd19"></a>
<a id="hevea_manual.kwd20"></a>
<a id="hevea_manual.kwd21"></a>
<a id="hevea_manual.kwd22"></a>
<a id="hevea_manual.kwd23"></a>
<a id="hevea_manual.kwd24"></a>
<a id="hevea_manual.kwd25"></a>
<a id="hevea_manual.kwd26"></a>
<a id="hevea_manual.kwd27"></a>
<a id="hevea_manual.kwd28"></a>
<a id="hevea_manual.kwd29"></a>
<a id="hevea_manual.kwd30"></a>
<a id="hevea_manual.kwd31"></a>
<a id="hevea_manual.kwd32"></a>
<a id="hevea_manual.kwd33"></a>
<a id="hevea_manual.kwd34"></a>
<a id="hevea_manual.kwd35"></a>
<a id="hevea_manual.kwd36"></a>
<a id="hevea_manual.kwd37"></a>
<a id="hevea_manual.kwd38"></a>
<a id="hevea_manual.kwd39"></a>
<a id="hevea_manual.kwd40"></a>
<a id="hevea_manual.kwd41"></a></p><table class="display dcenter"><tr class="c019"><td class="dcell"><table class="c001 cellpading0"><tr><td class="c018">
<a class="syntax" id="expr"><span class="c010">expr</span></a></td><td class="c015">::=</td><td class="c017">
<a class="syntax" href="names.html#value-path"><span class="c010">value-path</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="const.html#constant"><span class="c010">constant</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">(</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">)</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">begin</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">end</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">(</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">:</span>&#XA0;&#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>&#XA0;<span class="c004">)</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;&#XA0;{<span class="c004">,</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>}<sup>+</sup>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="names.html#constr"><span class="c010">constr</span></a>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">`</span><a class="syntax" href="names.html#tag-name"><span class="c010">tag-name</span></a>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">::</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">[</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;&#XA0;{&#XA0;<span class="c004">;</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;}&#XA0;&#XA0;[<span class="c004">;</span>]&#XA0;<span class="c004">]</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">[|</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;&#XA0;{&#XA0;<span class="c004">;</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;}&#XA0;&#XA0;[<span class="c004">;</span>]&#XA0;<span class="c004">|]</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">{</span>&#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a>&#XA0;&#XA0;[<span class="c004">:</span>&#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>]&#XA0;&#XA0;[<span class="c004">=</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>]&#XA0;{&#XA0;<span class="c004">;</span>&#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a>&#XA0;&#XA0;[<span class="c004">:</span>&#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>]&#XA0;&#XA0;[<span class="c004">=</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>]&#XA0;}&#XA0;&#XA0;[<span class="c004">;</span>]&#XA0;<span class="c004">}</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">{</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">with</span>&#XA0;&#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a>&#XA0;&#XA0;[<span class="c004">:</span>&#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>]&#XA0;&#XA0;[<span class="c004">=</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>]&#XA0;{&#XA0;<span class="c004">;</span>&#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a>&#XA0;&#XA0;[<span class="c004">:</span>&#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>]&#XA0;&#XA0;[<span class="c004">=</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>]&#XA0;}&#XA0;&#XA0;[<span class="c004">;</span>]&#XA0;<span class="c004">}</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;&#XA0;{&#XA0;<a class="syntax" href="#argument"><span class="c010">argument</span></a>&#XA0;}<sup>+</sup>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="lex.html#prefix-symbol"><span class="c010">prefix-symbol</span></a>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">-</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">-.</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;&#XA0;<a class="syntax" href="names.html#infix-op"><span class="c010">infix-op</span></a>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">.</span>&#XA0;&#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">.</span>&#XA0;&#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a>&#XA0;<span class="c004">&lt;-</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">.(</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">)</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">.(</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">)</span>&#XA0;<span class="c004">&lt;-</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">.[</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">]</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">.[</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">]</span>&#XA0;<span class="c004">&lt;-</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">if</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">then</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;&#XA0;[&#XA0;<span class="c004">else</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;]
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">while</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">do</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">done</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">for</span>&#XA0;<a class="syntax" href="names.html#value-name"><span class="c010">value-name</span></a>&#XA0;<span class="c004">=</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;&#XA0;(&#XA0;<span class="c004">to</span>&#XA0;&#X2223;&#XA0;&#XA0;<span class="c004">downto</span>&#XA0;)&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">do</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">done</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">;</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">match</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">with</span>&#XA0;&#XA0;<a class="syntax" href="#pattern-matching"><span class="c010">pattern-matching</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">function</span>&#XA0;<a class="syntax" href="#pattern-matching"><span class="c010">pattern-matching</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">fun</span>&#XA0;{&#XA0;<a class="syntax" href="#parameter"><span class="c010">parameter</span></a>&#XA0;}<sup>+</sup>&#XA0;&#XA0;[&#XA0;<span class="c004">:</span>&#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>&#XA0;]&#XA0;<span class="c004">-&gt;</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">try</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">with</span>&#XA0;&#XA0;<a class="syntax" href="#pattern-matching"><span class="c010">pattern-matching</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">let</span>&#XA0;[<span class="c004">rec</span>]&#XA0;<a class="syntax" href="#let-binding"><span class="c010">let-binding</span></a>&#XA0;&#XA0;{&#XA0;<span class="c004">and</span>&#XA0;<a class="syntax" href="#let-binding"><span class="c010">let-binding</span></a>&#XA0;}&#XA0;<span class="c004">in</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">new</span>&#XA0;<a class="syntax" href="names.html#class-path"><span class="c010">class-path</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">object</span>&#XA0;<a class="syntax" href="classes.html#class-body"><span class="c010">class-body</span></a>&#XA0;<span class="c004">end</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">#</span>&#XA0;&#XA0;<a class="syntax" href="names.html#method-name"><span class="c010">method-name</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="names.html#inst-var-name"><span class="c010">inst-var-name</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="names.html#inst-var-name"><span class="c010">inst-var-name</span></a>&#XA0;<span class="c004">&lt;-</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">(</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">:&gt;</span>&#XA0;&#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>&#XA0;<span class="c004">)</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">(</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">:</span>&#XA0;&#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>&#XA0;<span class="c004">:&gt;</span>&#XA0;&#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>&#XA0;<span class="c004">)</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">{&lt;</span>&#XA0;[&#XA0;<a class="syntax" href="names.html#inst-var-name"><span class="c010">inst-var-name</span></a>&#XA0;<span class="c004">=</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;&#XA0;{&#XA0;<span class="c004">;</span>&#XA0;<a class="syntax" href="names.html#inst-var-name"><span class="c010">inst-var-name</span></a>&#XA0;<span class="c004">=</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;}&#XA0;&#XA0;[<span class="c004">;</span>]&#XA0;]&#XA0;<span class="c004">&gt;}</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">assert</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">lazy</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">let</span>&#XA0;<span class="c004">module</span>&#XA0;<a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a>&#XA0;&#XA0;{&#XA0;<span class="c004">(</span>&#XA0;<a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a>&#XA0;<span class="c004">:</span>&#XA0;&#XA0;<a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a>&#XA0;<span class="c004">)</span>&#XA0;}
&#XA0;[&#XA0;<span class="c004">:</span>&#XA0;<a class="syntax" href="modtypes.html#module-type"><span class="c010">module-type</span></a>&#XA0;]&#XA0;&#XA0;<span class="c004">=</span>&#XA0;&#XA0;<a class="syntax" href="modules.html#module-expr"><span class="c010">module-expr</span></a>&#XA0;<span class="c004">in</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">let</span>&#XA0;<span class="c004">open</span>&#XA0;<a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a>&#XA0;<span class="c004">in</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a>&#XA0;<span class="c004">.(</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">)</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a>&#XA0;<span class="c004">.[</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">]</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a>&#XA0;<span class="c004">.[|</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">|]</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a>&#XA0;<span class="c004">.{</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">}</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a>&#XA0;<span class="c004">.{&lt;</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;<span class="c004">&gt;}</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td></tr>
</table></td></tr>
</table><table class="display dcenter"><tr class="c019"><td class="dcell"><table class="c001 cellpading0"><tr><td class="c018">
<a class="syntax" id="argument"><span class="c010">argument</span></a></td><td class="c015">::=</td><td class="c017">
<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">~</span>&#XA0;<a class="syntax" href="lex.html#label-name"><span class="c010">label-name</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">~</span>&#XA0;<a class="syntax" href="lex.html#label-name"><span class="c010">label-name</span></a>&#XA0;<span class="c004">:</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">?</span>&#XA0;<a class="syntax" href="lex.html#label-name"><span class="c010">label-name</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">?</span>&#XA0;<a class="syntax" href="lex.html#label-name"><span class="c010">label-name</span></a>&#XA0;<span class="c004">:</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td></tr>
<tr><td class="c018">
<a class="syntax" id="pattern-matching"><span class="c010">pattern-matching</span></a></td><td class="c015">::=</td><td class="c017">
[&#XA0;<span class="c004">|</span>&#XA0;]&#XA0;<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a>&#XA0;&#XA0;[<span class="c004">when</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>]&#XA0;<span class="c004">-&gt;</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;{&#XA0;<span class="c004">|</span>&#XA0;<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a>&#XA0;&#XA0;[<span class="c004">when</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>]&#XA0;<span class="c004">-&gt;</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;}
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td></tr>
<tr><td class="c018">
<a class="syntax" id="let-binding"><span class="c010">let-binding</span></a></td><td class="c015">::=</td><td class="c017">
<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a>&#XA0;<span class="c004">=</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="names.html#value-name"><span class="c010">value-name</span></a>&#XA0;&#XA0;{&#XA0;<a class="syntax" href="#parameter"><span class="c010">parameter</span></a>&#XA0;}&#XA0;&#XA0;[<span class="c004">:</span>&#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>]&#XA0;&#XA0;[<span class="c004">:&gt;</span>&#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>]&#XA0;<span class="c004">=</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<a class="syntax" href="names.html#value-name"><span class="c010">value-name</span></a>&#XA0;<span class="c004">:</span>&#XA0;&#XA0;<a class="syntax" href="types.html#poly-typexpr"><span class="c010">poly-typexpr</span></a>&#XA0;<span class="c004">=</span>&#XA0;&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>&#XA0;&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td></tr>
<tr><td class="c018">
<a class="syntax" id="parameter"><span class="c010">parameter</span></a></td><td class="c015">::=</td><td class="c017">
<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">~</span>&#XA0;<a class="syntax" href="lex.html#label-name"><span class="c010">label-name</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">~</span>&#XA0;<span class="c004">(</span>&#XA0;<a class="syntax" href="lex.html#label-name"><span class="c010">label-name</span></a>&#XA0;&#XA0;[<span class="c004">:</span>&#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>]&#XA0;<span class="c004">)</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">~</span>&#XA0;<a class="syntax" href="lex.html#label-name"><span class="c010">label-name</span></a>&#XA0;<span class="c004">:</span>&#XA0;&#XA0;<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">?</span>&#XA0;<a class="syntax" href="lex.html#label-name"><span class="c010">label-name</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">?</span>&#XA0;<span class="c004">(</span>&#XA0;<a class="syntax" href="lex.html#label-name"><span class="c010">label-name</span></a>&#XA0;&#XA0;[<span class="c004">:</span>&#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>]&#XA0;&#XA0;[<span class="c004">=</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>]&#XA0;<span class="c004">)</span>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">?</span>&#XA0;<a class="syntax" href="lex.html#label-name"><span class="c010">label-name</span></a>&#XA0;<span class="c004">:</span>&#XA0;&#XA0;<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a>
&#XA0;</td></tr>
<tr><td class="c018">&nbsp;</td><td class="c015">&#X2223;</td><td class="c017">&#XA0;<span class="c004">?</span>&#XA0;<a class="syntax" href="lex.html#label-name"><span class="c010">label-name</span></a>&#XA0;<span class="c004">:</span>&#XA0;<span class="c004">(</span>&#XA0;&#XA0;<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a>&#XA0;&#XA0;[<span class="c004">:</span>&#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>]&#XA0;&#XA0;[<span class="c004">=</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>]&#XA0;<span class="c004">)</span>
</td></tr>
</table></td></tr>
</table><p>
See also the following language extensions:
<a href="extn.html#s%3Aobject-notations">object notations</a>,
<a href="extn.html#s-first-class-modules">first-class modules</a>,
<a href="extn.html#s%3Aexplicit-overriding-open">overriding in open statements</a>,
<a href="extn.html#s%3Abigarray-access">syntax for Bigarray access</a>,
<a href="extn.html#s%3Aattributes">attributes</a>,
<a href="extn.html#s%3Aextension-nodes">extension nodes</a>,
<a href="extn.html#s%3Alocal-exceptions">local exceptions</a>
<a href="extn.html#s%3Aindex-operators">extended indexing operators</a>.</p><p>The table below shows the relative precedences and associativity of
operators and non-closed constructions. The constructions with higher
precedence come first. For infix and prefix symbols, we write
&#X201C;<span class="c003">*</span>&#X2026;&#X201D; to mean &#X201C;any symbol starting with <span class="c003">*</span>&#X201D;.
<a id="hevea_manual.kwd42"></a><a id="hevea_manual.kwd43"></a><a id="hevea_manual.kwd44"></a><a id="hevea_manual.kwd45"></a><a id="hevea_manual.kwd46"></a><a id="hevea_manual.kwd47"></a><a id="hevea_manual.kwd48"></a><a id="hevea_manual.kwd49"></a>
<a id="hevea_manual.kwd50"></a>
<a id="hevea_manual.kwd51"></a>
<a id="hevea_manual.kwd52"></a>
<a id="hevea_manual.kwd53"></a>
<a id="hevea_manual.kwd54"></a>
<a id="hevea_manual.kwd55"></a>
</p><div class="center"><table class="c000 cellpadding1" border=1><tr><td class="c014"><span class="c013">Construction or operator</span></td><td class="c014"><span class="c013">Associativity</span> </td></tr>
<tr><td class="c016">
prefix-symbol</td><td class="c016">&#X2013; </td></tr>
<tr><td class="c016"><span class="c003">.   .(   .[   .{</span> (see section&#XA0;<a href="extn.html#s%3Abigarray-access">8.15</a>)</td><td class="c016">&#X2013; </td></tr>
<tr><td class="c016"><span class="c003">#</span>&#X2026;</td><td class="c016">&#X2013; </td></tr>
<tr><td class="c016">function application, constructor application, tag
application, <span class="c003">assert</span>,
<span class="c003">lazy</span></td><td class="c016">left </td></tr>
<tr><td class="c016"><span class="c003">-   -.</span> (prefix)</td><td class="c016">&#X2013; </td></tr>
<tr><td class="c016"><span class="c003">**</span>&#X2026;<span class="c003">   lsl   lsr   asr</span></td><td class="c016">right </td></tr>
<tr><td class="c016"><span class="c003">*</span>&#X2026;<span class="c003">   /</span>&#X2026;<span class="c003">   %</span>&#X2026;<span class="c003">   mod   land   lor   lxor</span></td><td class="c016">left </td></tr>
<tr><td class="c016"> <span class="c003">+</span>&#X2026;<span class="c003">   -</span>&#X2026;</td><td class="c016">left </td></tr>
<tr><td class="c016"><span class="c003">::</span></td><td class="c016">right </td></tr>
<tr><td class="c016"><span class="c003">@</span>&#X2026;<span class="c003">   ^</span>&#X2026;</td><td class="c016">right </td></tr>
<tr><td class="c016"><span class="c003">=</span>&#X2026;<span class="c003">   &lt;</span>&#X2026;<span class="c003">   &gt;</span>&#X2026;<span class="c003">   |</span>&#X2026;<span class="c003">   &amp;</span>&#X2026;<span class="c003">   $</span>&#X2026;<span class="c003">   !=</span></td><td class="c016">left </td></tr>
<tr><td class="c016"><span class="c003">&amp;   &amp;&amp;</span></td><td class="c016">right </td></tr>
<tr><td class="c016"><span class="c003">or  ||</span></td><td class="c016">right </td></tr>
<tr><td class="c016"><span class="c003">,</span></td><td class="c016">&#X2013; </td></tr>
<tr><td class="c016"><span class="c003">&lt;-   :=</span></td><td class="c016">right </td></tr>
<tr><td class="c016"><span class="c003">if</span></td><td class="c016">&#X2013; </td></tr>
<tr><td class="c016"><span class="c003">;</span></td><td class="c016">right </td></tr>
<tr><td class="c016"><span class="c003">let  match  fun  function  try</span></td><td class="c016">&#X2013; </td></tr>
</table></div>
<h3 class="subsection" id="sec128">7.7.1&#XA0;&#XA0;Basic expressions</h3>
<h4 class="subsubsection" id="sec129">Constants</h4>
<p>An expression consisting in a constant evaluates to this constant.</p><h4 class="subsubsection" id="sec130">Value paths</h4>
<p> <a id="expr:var"></a></p><p>An expression consisting in an access path evaluates to the value bound to
this path in the current evaluation environment. The path can
be either a value name or an access path to a value component of a module.</p><h4 class="subsubsection" id="sec131">Parenthesized expressions</h4>
<p>
<a id="hevea_manual.kwd56"></a>
<a id="hevea_manual.kwd57"></a></p><p>The expressions <span class="c004">(</span> <a class="syntax" href="#expr"><span class="c010">expr</span></a> <span class="c004">)</span> and <span class="c004">begin</span> <a class="syntax" href="#expr"><span class="c010">expr</span></a> <span class="c004">end</span> have the same
value as <a class="syntax" href="#expr"><span class="c010">expr</span></a>. The two constructs are semantically equivalent, but it
is good style to use <span class="c004">begin</span> &#X2026; <span class="c004">end</span> inside control structures:
</p><pre>
        if &#X2026; then begin &#X2026; ; &#X2026; end else begin &#X2026; ; &#X2026; end
</pre><p>
and <span class="c004">(</span> &#X2026; <span class="c004">)</span> for the other grouping situations.</p><p>Parenthesized expressions can contain a type constraint, as in <span class="c004">(</span>
<a class="syntax" href="#expr"><span class="c010">expr</span></a> <span class="c004">:</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a> <span class="c004">)</span>. This constraint forces the type of <a class="syntax" href="#expr"><span class="c010">expr</span></a> to be
compatible with <a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>.</p><p>Parenthesized expressions can also contain coercions
<span class="c004">(</span> <a class="syntax" href="#expr"><span class="c010">expr</span></a> &#XA0;[<span class="c004">:</span> <a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>] <span class="c004">:&gt;</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a><span class="c004">)</span> (see
subsection&#XA0;<a href="#s%3Acoercions">7.7.6</a> below).</p><h4 class="subsubsection" id="sec132">Function application</h4>
<p>Function application is denoted by juxtaposition of (possibly labeled)
expressions. The expression <a class="syntax" href="#expr"><span class="c010">expr</span></a> &#XA0;<a class="syntax" href="#argument"><span class="c010">argument</span></a><sub>1</sub> &#X2026; &#XA0;<a class="syntax" href="#argument"><span class="c010">argument</span></a><sub><span class="c009">n</span></sub>
evaluates the expression <a class="syntax" href="#expr"><span class="c010">expr</span></a> and those appearing in <a class="syntax" href="#argument"><span class="c010">argument</span></a><sub>1</sub>
to <a class="syntax" href="#argument"><span class="c010">argument</span></a><sub><span class="c009">n</span></sub>. The expression <a class="syntax" href="#expr"><span class="c010">expr</span></a> must evaluate to a
functional value <span class="c009">f</span>, which is then applied to the values of
<a class="syntax" href="#argument"><span class="c010">argument</span></a><sub>1</sub>, &#X2026;, &#XA0;<a class="syntax" href="#argument"><span class="c010">argument</span></a><sub><span class="c009">n</span></sub>.</p><p>The order in which the expressions <a class="syntax" href="#expr"><span class="c010">expr</span></a>, &#XA0;<a class="syntax" href="#argument"><span class="c010">argument</span></a><sub>1</sub>, &#X2026;,
&#XA0;<a class="syntax" href="#argument"><span class="c010">argument</span></a><sub><span class="c009">n</span></sub> are evaluated is not specified.</p><p>Arguments and parameters are matched according to their respective
labels. Argument order is irrelevant, except among arguments with the
same label, or no label.</p><p>If a parameter is specified as optional (label prefixed by <span class="c004">?</span>) in the
type of <a class="syntax" href="#expr"><span class="c010">expr</span></a>, the corresponding argument will be automatically
wrapped with the constructor <span class="c003">Some</span>, except if the argument itself is
also prefixed by <span class="c004">?</span>, in which case it is passed as is.
If a non-labeled argument is passed, and its corresponding parameter
is preceded by one or several optional parameters, then these
parameters are <em>defaulted</em>, <em>i.e.</em> the value <span class="c003">None</span> will be
passed for them.
All other missing parameters (without corresponding argument), both
optional and non-optional, will be kept, and the result of the
function will still be a function of these missing parameters to the
body of <span class="c009">f</span>.</p><p>As a special case, if the function has a known arity, all the
arguments are unlabeled, and their number matches the number of
non-optional parameters, then labels are ignored and non-optional
parameters are matched in their definition order. Optional arguments
are defaulted.</p><p>In all cases but exact match of order and labels, without optional
parameters, the function type should be known at the application
point. This can be ensured by adding a type constraint. Principality
of the derivation can be checked in the <span class="c003">-principal</span> mode.</p><h4 class="subsubsection" id="sec133">Function definition</h4>
<p>Two syntactic forms are provided to define functions. The first form
is introduced by the keyword <span class="c003">function</span>:
<a id="hevea_manual.kwd58"></a></p><table class="display dcenter"><tr class="c019"><td class="dcell"><table class="c001 cellpading0"><tr><td class="c018"><span class="c004">function</span></td><td class="c017"><span class="c012">pattern</span><sub>1</sub></td><td class="c017"><span class="c004">-&gt;</span></td><td class="c017"><span class="c012">expr</span><sub>1</sub>&#XA0;</td></tr>
<tr><td class="c018"><span class="c004">|</span></td><td class="c017">&#X2026;&#XA0;</td></tr>
<tr><td class="c018"><span class="c004">|</span></td><td class="c017"><span class="c012">pattern</span><sub><span class="c009">n</span></sub></td><td class="c017"><span class="c004">-&gt;</span></td><td class="c017"><span class="c012">expr</span><sub><span class="c009">n</span></sub>
</td></tr>
</table></td></tr>
</table><p>
This expression evaluates to a functional value with one argument.
When this function is applied to a value <span class="c009">v</span>, this value is
matched against each pattern <a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub>1</sub> to <a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub><span class="c009">n</span></sub>.
If one of these matchings succeeds, that is, if the value <span class="c009">v</span>
matches the pattern <a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub><span class="c009">i</span></sub> for some <span class="c009">i</span>,
then the expression <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">i</span></sub> associated to the selected pattern
is evaluated, and its value becomes the value of the function
application. The evaluation of <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">i</span></sub> takes place in an
environment enriched by the bindings performed during the matching.</p><p>If several patterns match the argument <span class="c009">v</span>, the one that occurs
first in the function definition is selected. If none of the patterns
matches the argument, the exception <span class="c003">Match_failure</span> is raised.
<a id="hevea_manual0"></a></p><p><br>
</p><p>The other form of function definition is introduced by the keyword <span class="c003">fun</span>:
<a id="hevea_manual.kwd59"></a>
</p><div class="center">
<span class="c004">fun</span> <a class="syntax" href="#parameter"><span class="c010">parameter</span></a><sub>1</sub> &#X2026; &#XA0;<a class="syntax" href="#parameter"><span class="c010">parameter</span></a><sub><span class="c009">n</span></sub> <span class="c004">-&gt;</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
</div><p>
This expression is equivalent to:
</p><div class="center">
<span class="c004">fun</span> <a class="syntax" href="#parameter"><span class="c010">parameter</span></a><sub>1</sub> <span class="c004">-&gt;</span> &#X2026; <span class="c004">fun</span> &#XA0;<a class="syntax" href="#parameter"><span class="c010">parameter</span></a><sub><span class="c009">n</span></sub> <span class="c004">-&gt;</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
</div><p>An optional type constraint <a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a> can be added before <span class="c003">-&gt;</span> to enforce
the type of the result to be compatible with the constraint <a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>:
</p><div class="center">
<span class="c004">fun</span> <a class="syntax" href="#parameter"><span class="c010">parameter</span></a><sub>1</sub> &#X2026; &#XA0;<a class="syntax" href="#parameter"><span class="c010">parameter</span></a><sub><span class="c009">n</span></sub> <span class="c004">:</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a> <span class="c004">-&gt;</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
</div><p>
is equivalent to
</p><div class="center">
<span class="c004">fun</span> <a class="syntax" href="#parameter"><span class="c010">parameter</span></a><sub>1</sub> <span class="c004">-&gt;</span> &#X2026; <span class="c004">fun</span> &#XA0;<a class="syntax" href="#parameter"><span class="c010">parameter</span></a><sub><span class="c009">n</span></sub> <span class="c004">-&gt;</span> &#XA0;(<a class="syntax" href="#expr"><span class="c010">expr</span></a> <span class="c004">:</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a> )
</div><p>
Beware of the small syntactic difference between a type constraint on
the last parameter
</p><div class="center">
<span class="c004">fun</span> <a class="syntax" href="#parameter"><span class="c010">parameter</span></a><sub>1</sub> &#X2026; &#XA0;(<a class="syntax" href="#parameter"><span class="c010">parameter</span></a><sub><span class="c009">n</span></sub><span class="c004">:</span>&#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>)<span class="c004">-&gt;</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a> 
</div><p>
and one on the result
</p><div class="center">
<span class="c004">fun</span> <a class="syntax" href="#parameter"><span class="c010">parameter</span></a><sub>1</sub> &#X2026; &#XA0;<a class="syntax" href="#parameter"><span class="c010">parameter</span></a><sub><span class="c009">n</span></sub><span class="c004">:</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a> <span class="c004">-&gt;</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a> 
</div><p>The parameter patterns <span class="c004">~</span><a class="syntax" href="lex.html#label-name"><span class="c010">lab</span></a> and <span class="c004">~(</span><a class="syntax" href="lex.html#label-name"><span class="c010">lab</span></a> &#XA0;[<span class="c004">:</span> <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>]<span class="c004">)</span>
are shorthands for respectively <span class="c004">~</span><a class="syntax" href="lex.html#label-name"><span class="c010">lab</span></a><span class="c004">:</span>&#XA0;<a class="syntax" href="lex.html#label-name"><span class="c010">lab</span></a> and
<span class="c004">~</span><a class="syntax" href="lex.html#label-name"><span class="c010">lab</span></a><span class="c004">:(</span>&#XA0;<a class="syntax" href="lex.html#label-name"><span class="c010">lab</span></a> &#XA0;[<span class="c004">:</span> <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>]<span class="c004">)</span>, and similarly for their optional
counterparts.</p><p>A function of the form <span class="c002"><span class="c003">fun</span> <span class="c003">?</span></span> <a class="syntax" href="lex.html#label-name"><span class="c010">lab</span></a> <span class="c004">:(</span> &#XA0;<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a> <span class="c004">=</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>0</sub> <span class="c002"><span class="c003">)</span> <span class="c003">-&gt;</span></span>
&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a> is equivalent to
</p><div class="center">
<span class="c002"><span class="c003">fun</span> <span class="c003">?</span></span> <a class="syntax" href="lex.html#label-name"><span class="c010">lab</span></a> <span class="c004">:</span> &#XA0;<a class="syntax" href="lex.html#ident"><span class="c010">ident</span></a> <span class="c002"><span class="c003">-&gt;</span>
<span class="c003">let</span></span> &#XA0;<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a> <span class="c002"><span class="c003">=</span>
<span class="c003">match</span></span> &#XA0;<a class="syntax" href="lex.html#ident"><span class="c010">ident</span></a> <span class="c002"><span class="c003">with</span> <span class="c003">Some</span></span> &#XA0;<a class="syntax" href="lex.html#ident"><span class="c010">ident</span></a> <span class="c004">-&gt;</span> &#XA0;<a class="syntax" href="lex.html#ident"><span class="c010">ident</span></a> <span class="c002"><span class="c003">|</span> <span class="c003">None</span> <span class="c003">-&gt;</span></span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>0</sub>
<span class="c004">in</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
</div><p>
where <a class="syntax" href="lex.html#ident"><span class="c010">ident</span></a>
is a fresh variable, except that it is unspecified when <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>0</sub> is evaluated.</p><p>After these two transformations, expressions are of the form
</p><div class="center">
<span class="c004">fun</span> [<a class="syntax" href="lex.html#label"><span class="c010">label</span></a><sub>1</sub>] &#XA0;<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub>1</sub> <span class="c004">-&gt;</span> &#X2026; <span class="c004">fun</span> &#XA0;[<a class="syntax" href="lex.html#label"><span class="c010">label</span></a><sub><span class="c009">n</span></sub>] &#XA0;<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub><span class="c009">n</span></sub> <span class="c004">-&gt;</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
</div><p>
If we ignore labels, which will only be meaningful at function
application, this is equivalent to
</p><div class="center">
<span class="c004">function</span> <a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub>1</sub> <span class="c004">-&gt;</span> &#X2026; <span class="c004">function</span> &#XA0;<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub><span class="c009">n</span></sub> <span class="c004">-&gt;</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
</div><p>
That is, the <span class="c004">fun</span> expression above evaluates to a curried function
with <span class="c009">n</span> arguments: after applying this function <span class="c009">n</span> times to the
values <span class="c010">v</span><sub>1</sub> &#X2026; <span class="c010">v</span><sub><span class="c009">n</span></sub>, the values will be matched
in parallel against the patterns <a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub>1</sub> &#X2026; &#XA0;<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub><span class="c009">n</span></sub>.
If the matching succeeds, the function returns the value of <a class="syntax" href="#expr"><span class="c010">expr</span></a> in
an environment enriched by the bindings performed during the matchings.
If the matching fails, the exception <span class="c003">Match_failure</span> is raised.</p><h4 class="subsubsection" id="sec134">Guards in pattern-matchings</h4>
<p><a id="hevea_manual.kwd60"></a>
The cases of a pattern matching (in the <span class="c004">function</span>, <span class="c004">match</span> and
<span class="c004">try</span> constructs) can include guard expressions, which are
arbitrary boolean expressions that must evaluate to <span class="c003">true</span> for the
match case to be selected. Guards occur just before the <span class="c004">-&gt;</span> token and
are introduced by the <span class="c004">when</span> keyword:</p><table class="display dcenter"><tr class="c019"><td class="dcell"><table class="c001 cellpading0"><tr><td class="c018"><span class="c004">function</span></td><td class="c017"><span class="c010">pattern</span><sub>1</sub>&#XA0;&#XA0;&#XA0;[<span class="c004">when</span>&#XA0;&#XA0;&#XA0;<span class="c010">cond</span><sub>1</sub>]</td><td class="c017"><span class="c004">-&gt;</span></td><td class="c017"><span class="c010">expr</span><sub>1</sub>&#XA0;</td></tr>
<tr><td class="c018"><span class="c004">|</span></td><td class="c017">&#X2026;&#XA0;</td></tr>
<tr><td class="c018"><span class="c004">|</span></td><td class="c017"><span class="c010">pattern</span><sub><span class="c009">n</span></sub>&#XA0;&#XA0;&#XA0;&#XA0;[<span class="c004">when</span>&#XA0;&#XA0;&#XA0;<span class="c010">cond</span><sub><span class="c009">n</span></sub>]</td><td class="c017"><span class="c004">-&gt;</span></td><td class="c017"><span class="c010">expr</span><sub><span class="c009">n</span></sub>
</td></tr>
</table></td></tr>
</table><p>Matching proceeds as described before, except that if the value
matches some pattern <a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub><span class="c009">i</span></sub> which has a guard <span class="c010">cond</span><sub><span class="c009">i</span></sub>, then the
expression <span class="c010">cond</span><sub><span class="c009">i</span></sub> is evaluated (in an environment enriched by the
bindings performed during matching). If <span class="c010">cond</span><sub><span class="c009">i</span></sub> evaluates to <span class="c003">true</span>,
then <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">i</span></sub> is evaluated and its value returned as the result of the
matching, as usual. But if <span class="c010">cond</span><sub><span class="c009">i</span></sub> evaluates to <span class="c003">false</span>, the matching
is resumed against the patterns following <a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub><span class="c009">i</span></sub>.</p><h4 class="subsubsection" id="sec135">Local definitions</h4>
<p> <a id="s:localdef"></a></p><p><a id="hevea_manual.kwd61"></a></p><p>The <span class="c004">let</span> and <span class="c002"><span class="c003">let</span> <span class="c003">rec</span></span> constructs bind value names locally.
The construct
</p><div class="center">
<span class="c004">let</span> <a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub>1</sub> <span class="c004">=</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">and</span> &#X2026; <span class="c004">and</span> &#XA0;<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub><span class="c009">n</span></sub> <span class="c004">=</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub> <span class="c004">in</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
</div><p>
evaluates <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> &#X2026; &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub> in some unspecified order and matches
their values against the patterns <a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub>1</sub> &#X2026; &#XA0;<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub><span class="c009">n</span></sub>. If the
matchings succeed, <a class="syntax" href="#expr"><span class="c010">expr</span></a> is evaluated in the environment enriched by
the bindings performed during matching, and the value of <a class="syntax" href="#expr"><span class="c010">expr</span></a> is
returned as the value of the whole <span class="c004">let</span> expression. If one of the
matchings fails, the exception <span class="c003">Match_failure</span> is raised.
<a id="hevea_manual1"></a></p><p>An alternate syntax is provided to bind variables to functional
values: instead of writing
</p><div class="center">
<span class="c004">let</span> <a class="syntax" href="lex.html#ident"><span class="c010">ident</span></a> <span class="c002"><span class="c003">=</span> <span class="c003">fun</span></span> &#XA0;<a class="syntax" href="#parameter"><span class="c010">parameter</span></a><sub>1</sub> &#X2026; &#XA0;<a class="syntax" href="#parameter"><span class="c010">parameter</span></a><sub><span class="c009">m</span></sub> <span class="c004">-&gt;</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
</div><p>
in a <span class="c004">let</span> expression, one may instead write
</p><div class="center">
<span class="c004">let</span> <a class="syntax" href="lex.html#ident"><span class="c010">ident</span></a> &#XA0;<a class="syntax" href="#parameter"><span class="c010">parameter</span></a><sub>1</sub> &#X2026; &#XA0;<a class="syntax" href="#parameter"><span class="c010">parameter</span></a><sub><span class="c009">m</span></sub> <span class="c004">=</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
</div><p><br>
Recursive definitions of names are introduced by <span class="c002"><span class="c003">let</span> <span class="c003">rec</span></span>:
</p><div class="center">
<span class="c002"><span class="c003">let</span> <span class="c003">rec</span></span> <a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub>1</sub> <span class="c004">=</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">and</span> &#X2026; <span class="c004">and</span> &#XA0;<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub><span class="c009">n</span></sub> <span class="c004">=</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub>
<span class="c004">in</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
</div><p>
The only difference with the <span class="c004">let</span> construct described above is
that the bindings of names to values performed by the
pattern-matching are considered already performed when the expressions
<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> to <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub> are evaluated. That is, the expressions <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub>
to <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub> can reference identifiers that are bound by one of the
patterns <a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub>1</sub>, &#X2026;, &#XA0;<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub><span class="c009">n</span></sub>, and expect them to have the
same value as in <a class="syntax" href="#expr"><span class="c010">expr</span></a>, the body of the <span class="c002"><span class="c003">let</span> <span class="c003">rec</span></span> construct.</p><p>The recursive definition is guaranteed to behave as described above if
the expressions <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> to <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub> are function definitions
(<span class="c004">fun</span> &#X2026; or <span class="c004">function</span> &#X2026;), and the patterns <a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub>1</sub>
&#X2026; &#XA0;<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub><span class="c009">n</span></sub> are just value names, as in:
</p><div class="center">
<span class="c002"><span class="c003">let</span> <span class="c003">rec</span></span> <span class="c010">name</span><sub>1</sub> <span class="c002"><span class="c003">=</span> <span class="c003">fun</span></span> &#X2026;
<span class="c004">and</span> &#X2026;
<span class="c004">and</span> &#XA0;<span class="c010">name</span><sub><span class="c009">n</span></sub> <span class="c002"><span class="c003">=</span> <span class="c003">fun</span></span> &#X2026;
<span class="c004">in</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
</div><p>
This defines <span class="c010">name</span><sub>1</sub> &#X2026; &#XA0;<span class="c010">name</span><sub><span class="c009">n</span></sub> as mutually recursive functions
local to <a class="syntax" href="#expr"><span class="c010">expr</span></a>.</p><p>The behavior of other forms of <span class="c002"><span class="c003">let</span> <span class="c003">rec</span></span> definitions is
implementation-dependent. The current implementation also supports
a certain class of recursive definitions of non-functional values,
as explained in section&#XA0;<a href="extn.html#s%3Aletrecvalues">8.2</a>.
</p>
<h4 class="subsubsection" id="sec136">Explicit polymorphic type annotations</h4>
<p>
(Introduced in OCaml 3.12)</p><p>Polymorphic type annotations in <span class="c004">let</span>-definitions behave in a way
similar to polymorphic methods:</p><div class="center">
<span class="c004">let</span> <a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub>1</sub> <span class="c004">:</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>1</sub> &#X2026; &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub><span class="c009">n</span></sub> <span class="c004">.</span> &#XA0;<span class="c010">typeexpr</span> <span class="c004">=</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a> 
</div><p>These annotations explicitly require the defined value to be polymorphic,
and allow one to use this polymorphism in recursive occurrences
(when using <span class="c002"><span class="c003">let</span> <span class="c003">rec</span></span>). Note however that this is a normal polymorphic
type, unifiable with any instance of itself.</p>
<h3 class="subsection" id="sec137">7.7.2&#XA0;&#XA0;Control structures</h3>
<h4 class="subsubsection" id="sec138">Sequence</h4>
<p>The expression <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">;</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> evaluates <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> first, then
<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub>, and returns the value of <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub>.</p><h4 class="subsubsection" id="sec139">Conditional</h4>
<p>
<a id="hevea_manual.kwd62"></a></p><p>The expression <span class="c004">if</span> <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">then</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> <span class="c004">else</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>3</sub> evaluates to
the value of <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> if <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> evaluates to the boolean <span class="c004">true</span>,
and to the value of <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>3</sub> if <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> evaluates to the boolean
<span class="c004">false</span>.</p><p>The <span class="c004">else</span> <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>3</sub> part can be omitted, in which case it defaults to
<span class="c002"><span class="c003">else</span> <span class="c003">()</span></span>.</p><h4 class="subsubsection" id="sec140">Case expression</h4>
<p><a id="hevea_manual.kwd63"></a></p><p>The expression
</p><table class="display dcenter"><tr class="c019"><td class="dcell"><table class="c001 cellpading0"><tr><td class="c018"><span class="c004">match</span></td><td class="c017"><span class="c012">expr</span>&#XA0;</td></tr>
<tr><td class="c018"><span class="c004">with</span></td><td class="c017"><span class="c012">pattern</span><sub>1</sub></td><td class="c017"><span class="c004">-&gt;</span></td><td class="c017"><span class="c012">expr</span><sub>1</sub>&#XA0;</td></tr>
<tr><td class="c018"><span class="c004">|</span></td><td class="c017">&#X2026;&#XA0;</td></tr>
<tr><td class="c018"><span class="c004">|</span></td><td class="c017"><span class="c012">pattern</span><sub><span class="c009">n</span></sub></td><td class="c017"><span class="c004">-&gt;</span></td><td class="c017"><span class="c012">expr</span><sub><span class="c009">n</span></sub>
</td></tr>
</table></td></tr>
</table><p>
matches the value of <a class="syntax" href="#expr"><span class="c010">expr</span></a> against the patterns <a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub>1</sub> to
<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub><span class="c009">n</span></sub>. If the matching against <a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub><span class="c009">i</span></sub> succeeds, the
associated expression <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">i</span></sub> is evaluated, and its value becomes the
value of the whole <span class="c004">match</span> expression. The evaluation of
<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">i</span></sub> takes place in an environment enriched by the bindings
performed during matching. If several patterns match the value of
<a class="syntax" href="#expr"><span class="c010">expr</span></a>, the one that occurs first in the <span class="c004">match</span> expression is
selected. If none of the patterns match the value of <a class="syntax" href="#expr"><span class="c010">expr</span></a>, the
exception <span class="c003">Match_failure</span> is raised.
<a id="hevea_manual2"></a></p><h4 class="subsubsection" id="sec141">Boolean operators</h4>
<p>The expression <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">&amp;&amp;</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> evaluates to <span class="c004">true</span> if both
<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> and <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> evaluate to <span class="c004">true</span>; otherwise, it evaluates to
<span class="c004">false</span>. The first component, <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub>, is evaluated first. The
second component, <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub>, is not evaluated if the first component
evaluates to <span class="c004">false</span>. Hence, the expression <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">&amp;&amp;</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> behaves
exactly as
</p><div class="center">
<span class="c004">if</span> <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">then</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> <span class="c002"><span class="c003">else</span> <span class="c003">false</span></span>.
</div><p>The expression <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">||</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> evaluates to <span class="c004">true</span> if one of
the expressions
<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> and <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> evaluates to <span class="c004">true</span>; otherwise, it evaluates to
<span class="c004">false</span>. The first component, <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub>, is evaluated first. The
second component, <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub>, is not evaluated if the first component
evaluates to <span class="c004">true</span>. Hence, the expression <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">||</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> behaves
exactly as
</p><div class="center">
<span class="c004">if</span> <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c002"><span class="c003">then</span> <span class="c003">true</span> <span class="c003">else</span></span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub>.
</div><p><a id="hevea_manual.kwd64"></a>
The boolean operators <span class="c004">&amp;</span> and <span class="c004">or</span> are deprecated synonyms for
(respectively) <span class="c004">&amp;&amp;</span> and <span class="c004">||</span>.</p><h4 class="subsubsection" id="sec142">Loops</h4>
<p><a id="hevea_manual.kwd65"></a>
The expression <span class="c004">while</span> <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">do</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> <span class="c004">done</span> repeatedly
evaluates <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> while <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> evaluates to <span class="c004">true</span>. The loop
condition <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> is evaluated and tested at the beginning of each
iteration. The whole <span class="c004">while</span> &#X2026; <span class="c004">done</span> expression evaluates to
the unit value <span class="c004">()</span>.</p><p><a id="hevea_manual.kwd66"></a>
The expression <span class="c002"><span class="c003">for</span> <span class="c010">name</span> <span class="c003">=</span></span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">to</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> <span class="c004">do</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>3</sub> <span class="c004">done</span>
first evaluates the expressions <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> and <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> (the boundaries)
into integer values <span class="c009">n</span> and <span class="c009">p</span>. Then, the loop body <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>3</sub> is
repeatedly evaluated in an environment where <span class="c010">name</span> is successively
bound to the values
<span class="c009">n</span>, <span class="c009">n</span>+1, &#X2026;, <span class="c009">p</span>&#X2212;1, <span class="c009">p</span>.
The loop body is never evaluated if <span class="c009">n</span> &gt; <span class="c009">p</span>.</p><p>The expression <span class="c002"><span class="c003">for</span> <span class="c010">name</span> <span class="c003">=</span></span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">downto</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> <span class="c004">do</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>3</sub> <span class="c004">done</span>
evaluates similarly, except that <span class="c010">name</span> is successively bound to the values
<span class="c009">n</span>, <span class="c009">n</span>&#X2212;1, &#X2026;, <span class="c009">p</span>+1, <span class="c009">p</span>.
The loop body is never evaluated if <span class="c009">n</span> &lt; <span class="c009">p</span>.</p><p>In both cases, the whole <span class="c004">for</span> expression evaluates to the unit
value <span class="c004">()</span>.</p><h4 class="subsubsection" id="sec143">Exception handling</h4>
<p>
<a id="hevea_manual.kwd67"></a></p><p>The expression
</p><table class="display dcenter"><tr class="c019"><td class="dcell"><table class="c001 cellpading0"><tr><td class="c018"><span class="c004">try&#XA0;</span></td><td class="c017"><span class="c012">expr</span>&#XA0;</td></tr>
<tr><td class="c018"><span class="c004">with</span></td><td class="c017"><span class="c012">pattern</span><sub>1</sub></td><td class="c017"><span class="c004">-&gt;</span></td><td class="c017"><span class="c012">expr</span><sub>1</sub>&#XA0;</td></tr>
<tr><td class="c018"><span class="c004">|</span></td><td class="c017">&#X2026;&#XA0;</td></tr>
<tr><td class="c018"><span class="c004">|</span></td><td class="c017"><span class="c012">pattern</span><sub><span class="c009">n</span></sub></td><td class="c017"><span class="c004">-&gt;</span></td><td class="c017"><span class="c012">expr</span><sub><span class="c009">n</span></sub>
</td></tr>
</table></td></tr>
</table><p>
evaluates the expression <a class="syntax" href="#expr"><span class="c010">expr</span></a> and returns its value if the
evaluation of <a class="syntax" href="#expr"><span class="c010">expr</span></a> does not raise any exception. If the evaluation
of <a class="syntax" href="#expr"><span class="c010">expr</span></a> raises an exception, the exception value is matched against
the patterns <a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub>1</sub> to <a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub><span class="c009">n</span></sub>. If the matching against
<a class="syntax" href="patterns.html#pattern"><span class="c010">pattern</span></a><sub><span class="c009">i</span></sub> succeeds, the associated expression <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">i</span></sub> is evaluated,
and its value becomes the value of the whole <span class="c004">try</span> expression. The
evaluation of <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">i</span></sub> takes place in an environment enriched by the
bindings performed during matching. If several patterns match the value of
<a class="syntax" href="#expr"><span class="c010">expr</span></a>, the one that occurs first in the <span class="c004">try</span> expression is
selected. If none of the patterns matches the value of <a class="syntax" href="#expr"><span class="c010">expr</span></a>, the
exception value is raised again, thereby transparently &#X201C;passing
through&#X201D; the <span class="c004">try</span> construct.</p>
<h3 class="subsection" id="sec144">7.7.3&#XA0;&#XA0;Operations on data structures</h3>
<h4 class="subsubsection" id="sec145">Products</h4>
<p>The expression <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">,</span> &#X2026; <span class="c004">,</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub> evaluates to the
<span class="c009">n</span>-tuple of the values of expressions <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> to <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub>. The
evaluation order of the subexpressions is not specified.</p><h4 class="subsubsection" id="sec146">Variants</h4>
<p>The expression <a class="syntax" href="names.html#constr"><span class="c010">constr</span></a> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a> evaluates to the unary variant value
whose constructor is <a class="syntax" href="names.html#constr"><span class="c010">constr</span></a>, and whose argument is the value of
<a class="syntax" href="#expr"><span class="c010">expr</span></a>. Similarly, the expression <a class="syntax" href="names.html#constr"><span class="c010">constr</span></a> <span class="c004">(</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">,</span> &#X2026; <span class="c004">,</span>
&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub> <span class="c004">)</span> evaluates to the n-ary variant value whose constructor is
<a class="syntax" href="names.html#constr"><span class="c010">constr</span></a> and whose arguments are the values of <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub>, &#X2026;,
&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub>.</p><p>The expression <a class="syntax" href="names.html#constr"><span class="c010">constr</span></a> <span class="c004">(</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub>, &#X2026;, &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub><span class="c004">)</span> evaluates to the
variant value whose constructor is <a class="syntax" href="names.html#constr"><span class="c010">constr</span></a>, and whose arguments are
the values of <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> &#X2026; &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub>.</p><p>For lists, some syntactic sugar is provided. The expression
<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">::</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> stands for the constructor <span class="c002"><span class="c003">(</span> <span class="c003">::</span> <span class="c003">)</span></span> 
applied to the arguments <span class="c004">(</span> <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">,</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> <span class="c004">)</span>, and therefore
evaluates to the list whose head is the value of <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> and whose tail
is the value of <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub>. The expression <span class="c004">[</span> <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">;</span> &#X2026; <span class="c004">;</span>
&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub> <span class="c004">]</span> is equivalent to <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">::</span> &#X2026; <span class="c004">::</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub> <span class="c002"><span class="c003">::</span>
<span class="c003">[]</span></span>, and therefore evaluates to the list whose elements are the
values of <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> to <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub>.</p><h4 class="subsubsection" id="sec147">Polymorphic variants</h4>
<p>The expression <span class="c004">`</span><a class="syntax" href="names.html#tag-name"><span class="c010">tag-name</span></a> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a> evaluates to the polymorphic variant
value whose tag is <a class="syntax" href="names.html#tag-name"><span class="c010">tag-name</span></a>, and whose argument is the value of <a class="syntax" href="#expr"><span class="c010">expr</span></a>.</p><h4 class="subsubsection" id="sec148">Records</h4>
<p>The expression <span class="c004">{</span> <a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub>1</sub> &#XA0;[<span class="c004">=</span> <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub>] <span class="c004">;</span> &#X2026; <span class="c004">;</span> &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">n</span></sub> &#XA0;[<span class="c004">=</span>
<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub> <span class="c004">]}</span> evaluates to the record value
{ <span class="c009">field</span><sub>1</sub> = <span class="c009">v</span><sub>1</sub>; &#X2026;; <span class="c009">field</span><sub><span class="c009">n</span></sub> = <span class="c009">v</span><sub><span class="c009">n</span></sub> }
where <span class="c009">v</span><sub><span class="c009">i</span></sub> is the value of <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">i</span></sub> for <span class="c009">i</span> = 1,&#X2026; , <span class="c009">n</span>.
A single identifier <a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">k</span></sub> stands for <a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">k</span></sub> <span class="c004">=</span> &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">k</span></sub>,
and a qualified identifier <a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a> <span class="c004">.</span> &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">k</span></sub> stands for
<a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a> <span class="c004">.</span> &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">k</span></sub> <span class="c004">=</span> &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">k</span></sub>.
The fields <a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub>1</sub> to <a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">n</span></sub> must all belong to the same record
type; each field of this record type must appear exactly
once in the record expression, though they can appear in any
order. The order in which <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> to <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub> are evaluated is not
specified. Optional type constraints can be added after each field
<span class="c004">{</span> <a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub>1</sub> <span class="c004">:</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a><sub>1</sub> <span class="c004">=</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">;</span>&#X2026; <span class="c004">;</span> &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">n</span></sub> <span class="c004">:</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a><sub><span class="c009">n</span></sub> <span class="c004">=</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub> <span class="c004">}</span>
to force the type of <a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">k</span></sub> to be compatible with <a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a><sub><span class="c009">k</span></sub>.</p><p>The expression
<span class="c004">{</span> <a class="syntax" href="#expr"><span class="c010">expr</span></a> <span class="c004">with</span> &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub>1</sub> &#XA0;[<span class="c004">=</span> <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub>] <span class="c004">;</span> &#X2026; <span class="c004">;</span> &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">n</span></sub> &#XA0;[<span class="c004">=</span> <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub>] <span class="c004">}</span>
builds a fresh record with fields <a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub>1</sub> &#X2026; &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">n</span></sub> equal to
<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> &#X2026; &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub>, and all other fields having the same value as
in the record <a class="syntax" href="#expr"><span class="c010">expr</span></a>. In other terms, it returns a shallow copy of
the record <a class="syntax" href="#expr"><span class="c010">expr</span></a>, except for the fields <a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub>1</sub> &#X2026; &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">n</span></sub>,
which are initialized to <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> &#X2026; &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub>. As previously,
single identifier <a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">k</span></sub> stands for <a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">k</span></sub> <span class="c004">=</span> &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">k</span></sub>,
a qualified identifier <a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a> <span class="c004">.</span> &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">k</span></sub> stands for
<a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a> <span class="c004">.</span> &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">k</span></sub> <span class="c004">=</span> &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">k</span></sub> and it is
possible to add an optional type constraint on each field being updated
with
<span class="c004">{</span> <a class="syntax" href="#expr"><span class="c010">expr</span></a> <span class="c004">with</span> &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub>1</sub> <span class="c004">:</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a><sub>1</sub> <span class="c004">=</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">;</span> &#X2026; <span class="c004">;</span> &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a><sub><span class="c009">n</span></sub> <span class="c004">:</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a><sub><span class="c009">n</span></sub> <span class="c004">=</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub> <span class="c004">}</span>.</p><p>The expression <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">.</span> &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a> evaluates <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> to a record
value, and returns the value associated to <a class="syntax" href="names.html#field"><span class="c010">field</span></a> in this record
value.</p><p>The expression <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">.</span> &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a> <span class="c004">&lt;-</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> evaluates <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> to a record
value, which is then modified in-place by replacing the value
associated to <a class="syntax" href="names.html#field"><span class="c010">field</span></a> in this record by the value of
<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub>. This operation is permitted only if <a class="syntax" href="names.html#field"><span class="c010">field</span></a> has been
declared <span class="c004">mutable</span> in the definition of the record type. The whole
expression <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">.</span> &#XA0;<a class="syntax" href="names.html#field"><span class="c010">field</span></a> <span class="c004">&lt;-</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> evaluates to the unit value
<span class="c004">()</span>.</p><h4 class="subsubsection" id="sec149">Arrays</h4>
<p>The expression <span class="c004">[|</span> <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">;</span> &#X2026; <span class="c004">;</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub> <span class="c004">|]</span> evaluates to
a <span class="c009">n</span>-element array, whose elements are initialized with the values of
<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> to <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub><span class="c009">n</span></sub> respectively. The order in which these
expressions are evaluated is unspecified.</p><p>The expression <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">.(</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> <span class="c004">)</span> returns the value of element
number <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> in the array denoted by <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub>. The first element
has number 0; the last element has number <span class="c009">n</span>&#X2212;1, where <span class="c009">n</span> is the
size of the array. The exception <span class="c003">Invalid_argument</span> is raised if the
access is out of bounds.</p><p>The expression <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">.(</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> <span class="c002"><span class="c003">)</span> <span class="c003">&lt;-</span></span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>3</sub> modifies in-place
the array denoted by <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub>, replacing element number <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> by
the value of <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>3</sub>. The exception <span class="c003">Invalid_argument</span> is raised if
the access is out of bounds. The value of the whole expression is <span class="c004">()</span>.</p><h4 class="subsubsection" id="sec150">Strings</h4>
<p>The expression <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">.[</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> <span class="c004">]</span> returns the value of character
number <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> in the string denoted by <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub>. The first character
has number 0; the last character has number <span class="c009">n</span>&#X2212;1, where <span class="c009">n</span> is the
length of the string. The exception <span class="c003">Invalid_argument</span> is raised if the
access is out of bounds.</p><p>The expression <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> <span class="c004">.[</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> <span class="c002"><span class="c003">]</span> <span class="c003">&lt;-</span></span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>3</sub> modifies in-place
the string denoted by <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub>, replacing character number <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> by
the value of <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>3</sub>. The exception <span class="c003">Invalid_argument</span> is raised if
the access is out of bounds. The value of the whole expression is <span class="c004">()</span>.</p><p><span class="c013">Note:</span> this possibility is offered only for backward
compatibility with older versions of OCaml and will be removed in a
future version. New code should use byte sequences and the <span class="c003">Bytes.set</span>
function.</p>
<h3 class="subsection" id="sec151">7.7.4&#XA0;&#XA0;Operators</h3>
<p>
<a id="hevea_manual.kwd68"></a>
<a id="hevea_manual.kwd69"></a>
<a id="hevea_manual.kwd70"></a>
<a id="hevea_manual.kwd71"></a>
<a id="hevea_manual.kwd72"></a>
<a id="hevea_manual.kwd73"></a>
<a id="hevea_manual.kwd74"></a></p><p>Symbols from the class <a class="syntax" href="lex.html#infix-symbol"><span class="c010">infix-symbol</span></a>, as well as the keywords
<span class="c004">*</span>, <span class="c004">+</span>, <span class="c004">-</span>, <span class="c004">-.</span>, <span class="c004">=</span>, <span class="c004">!=</span>, <span class="c004">&lt;</span>, <span class="c004">&gt;</span>, <span class="c004">or</span>, <span class="c004">||</span>,
<span class="c004">&amp;</span>, <span class="c004">&amp;&amp;</span>, <span class="c004">:=</span>, <span class="c004">mod</span>, <span class="c004">land</span>, <span class="c004">lor</span>, <span class="c004">lxor</span>, <span class="c004">lsl</span>, <span class="c004">lsr</span>,
and <span class="c004">asr</span> can appear in infix position (between two
expressions). Symbols from the class <a class="syntax" href="lex.html#prefix-symbol"><span class="c010">prefix-symbol</span></a>, as well as
the keywords <span class="c004">-</span> and <span class="c004">-.</span>
can appear in prefix position (in front of an expression).</p><p>Infix and prefix symbols do not have a fixed meaning: they are simply
interpreted as applications of functions bound to the names
corresponding to the symbols. The expression <a class="syntax" href="lex.html#prefix-symbol"><span class="c010">prefix-symbol</span></a> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a> is
interpreted as the application <span class="c004">(</span> <a class="syntax" href="lex.html#prefix-symbol"><span class="c010">prefix-symbol</span></a> <span class="c004">)</span>
&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>. Similarly, the expression <a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> &#XA0;<a class="syntax" href="lex.html#infix-symbol"><span class="c010">infix-symbol</span></a> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub> is
interpreted as the application <span class="c004">(</span> <a class="syntax" href="lex.html#infix-symbol"><span class="c010">infix-symbol</span></a> <span class="c004">)</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>1</sub> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><sub>2</sub>.</p><p>The table below lists the symbols defined in the initial environment
and their initial meaning. (See the description of the core
library module <span class="c003">Pervasives</span> in chapter&#XA0;<a href="core.html#c%3Acorelib">25</a> for more
details). Their meaning may be changed at any time using
<span class="c002"><span class="c003">let</span> <span class="c003">(</span></span> <a class="syntax" href="names.html#infix-op"><span class="c010">infix-op</span></a> <span class="c004">)</span> &#XA0;<span class="c010">name</span><sub>1</sub> &#XA0;<span class="c010">name</span><sub>2</sub> <span class="c004">=</span> &#X2026;</p><p>Note: the operators <span class="c004">&amp;&amp;</span>, <span class="c004">||</span>, and <span class="c004">~-</span> are handled specially
and it is not advisable to change their meaning.</p><p>The keywords <span class="c004">-</span> and <span class="c004">-.</span> can appear both as infix and
prefix operators. When they appear as prefix operators, they are
interpreted respectively as the functions <span class="c004">(~-)</span> and <span class="c004">(~-.)</span>.</p><p><a id="hevea_manual.kwd75"></a><a id="hevea_manual.kwd76"></a><a id="hevea_manual.kwd77"></a><a id="hevea_manual.kwd78"></a><a id="hevea_manual.kwd79"></a><a id="hevea_manual.kwd80"></a><a id="hevea_manual.kwd81"></a></p><div class="center"><table class="c000 cellpadding1" border=1><tr><td class="c014"><span class="c013">Operator</span></td><td class="c014"><span class="c013">Initial meaning</span> </td></tr>
<tr><td class="c022">
<span class="c003">+</span></td><td class="c021">Integer addition. </td></tr>
<tr><td class="c022"><span class="c003">-</span> (infix)</td><td class="c021">Integer subtraction. </td></tr>
<tr><td class="c022"><span class="c003">~-   -</span> (prefix)</td><td class="c021">Integer negation. </td></tr>
<tr><td class="c022"><span class="c003">*</span></td><td class="c021">Integer multiplication. </td></tr>
<tr><td class="c022"><span class="c003">/</span></td><td class="c021">Integer division.
Raise <span class="c003">Division_by_zero</span> if second argument is zero. </td></tr>
<tr><td class="c022"><span class="c003">mod</span></td><td class="c021">Integer modulus. Raise
<span class="c003">Division_by_zero</span> if second argument is zero. </td></tr>
<tr><td class="c022"><span class="c003">land</span></td><td class="c021">Bitwise logical &#X201C;and&#X201D; on integers. </td></tr>
<tr><td class="c022"><span class="c003">lor</span></td><td class="c021">Bitwise logical &#X201C;or&#X201D; on integers. </td></tr>
<tr><td class="c022"><span class="c003">lxor</span></td><td class="c021">Bitwise logical &#X201C;exclusive or&#X201D; on integers. </td></tr>
<tr><td class="c022"><span class="c003">lsl</span></td><td class="c021">Bitwise logical shift left on integers. </td></tr>
<tr><td class="c022"><span class="c003">lsr</span></td><td class="c021">Bitwise logical shift right on integers. </td></tr>
<tr><td class="c022"><span class="c003">asr</span></td><td class="c021">Bitwise arithmetic shift right on integers. </td></tr>
<tr><td class="c022"><span class="c003">+.</span></td><td class="c021">Floating-point addition. </td></tr>
<tr><td class="c022"><span class="c003">-.</span> (infix)</td><td class="c021">Floating-point subtraction. </td></tr>
<tr><td class="c022"><span class="c003">~-.   -.</span> (prefix)</td><td class="c021">Floating-point negation. </td></tr>
<tr><td class="c022"><span class="c003">*.</span></td><td class="c021">Floating-point multiplication. </td></tr>
<tr><td class="c022"><span class="c003">/.</span></td><td class="c021">Floating-point division. </td></tr>
<tr><td class="c022"><span class="c003">**</span></td><td class="c021">Floating-point exponentiation. </td></tr>
<tr><td class="c022"><span class="c003">@</span> </td><td class="c021">List concatenation. </td></tr>
<tr><td class="c022"><span class="c003">^</span> </td><td class="c021">String concatenation. </td></tr>
<tr><td class="c022"><span class="c003">!</span> </td><td class="c021">Dereferencing (return the current
contents of a reference). </td></tr>
<tr><td class="c022"><span class="c003">:=</span></td><td class="c021">Reference assignment (update the
reference given as first argument with the value of the second
argument). </td></tr>
<tr><td class="c022"><span class="c003">=</span> </td><td class="c021">Structural equality test. </td></tr>
<tr><td class="c022"><span class="c003">&lt;&gt;</span> </td><td class="c021">Structural inequality test. </td></tr>
<tr><td class="c022"><span class="c003">==</span> </td><td class="c021">Physical equality test. </td></tr>
<tr><td class="c022"><span class="c003">!=</span> </td><td class="c021">Physical inequality test. </td></tr>
<tr><td class="c022"><span class="c003">&lt;</span> </td><td class="c021">Test &#X201C;less than&#X201D;. </td></tr>
<tr><td class="c022"><span class="c003">&lt;=</span> </td><td class="c021">Test &#X201C;less than or equal&#X201D;. </td></tr>
<tr><td class="c022"><span class="c003">&gt;</span> </td><td class="c021">Test &#X201C;greater than&#X201D;. </td></tr>
<tr><td class="c022"><span class="c003">&gt;=</span> </td><td class="c021">Test &#X201C;greater than or equal&#X201D;. </td></tr>
<tr><td class="c022"><span class="c003">&amp;&amp;   &amp;</span></td><td class="c021">Boolean conjunction. </td></tr>
<tr><td class="c022"><span class="c003">||   or</span></td><td class="c021">Boolean disjunction. </td></tr>
</table></div>
<h3 class="subsection" id="sec152">7.7.5&#XA0;&#XA0;Objects</h3>
<p> <a id="s:objects"></a></p><h4 class="subsubsection" id="sec153">Object creation</h4>
<p><a id="hevea_manual.kwd82"></a></p><p>When <a class="syntax" href="names.html#class-path"><span class="c010">class-path</span></a> evaluates to a class body, <span class="c004">new</span> <a class="syntax" href="names.html#class-path"><span class="c010">class-path</span></a>
evaluates to a new object containing the instance variables and
methods of this class.</p><p>When <a class="syntax" href="names.html#class-path"><span class="c010">class-path</span></a> evaluates to a class function, <span class="c004">new</span> <a class="syntax" href="names.html#class-path"><span class="c010">class-path</span></a>
evaluates to a function expecting the same number of arguments and
returning a new object of this class.</p><h4 class="subsubsection" id="sec154">Immediate object creation</h4>
<p><a id="hevea_manual.kwd83"></a></p><p>Creating directly an object through the <span class="c004">object</span> <a class="syntax" href="classes.html#class-body"><span class="c010">class-body</span></a> <span class="c004">end</span>
construct is operationally equivalent to defining locally a <span class="c004">class</span>
<a class="syntax" href="names.html#class-name"><span class="c010">class-name</span></a> <span class="c002"><span class="c003">=</span> <span class="c003">object</span></span> &#XA0;<a class="syntax" href="classes.html#class-body"><span class="c010">class-body</span></a> <span class="c004">end</span> &#X2014;see sections
<a href="classes.html#ss%3Aclass-body">7.9.2</a> and following for the syntax of <a class="syntax" href="classes.html#class-body"><span class="c010">class-body</span></a>&#X2014;
and immediately creating a single object from it by <span class="c004">new</span> <a class="syntax" href="names.html#class-name"><span class="c010">class-name</span></a>.</p><p>The typing of immediate objects is slightly different from explicitly
defining a class in two respects. First, the inferred object type may
contain free type variables. Second, since the class body of an
immediate object will never be extended, its self type can be unified
with a closed object type.</p><h4 class="subsubsection" id="sec155">Method invocation</h4>
<p>The expression <a class="syntax" href="#expr"><span class="c010">expr</span></a> <span class="c004">#</span> &#XA0;<a class="syntax" href="names.html#method-name"><span class="c010">method-name</span></a> invokes the method
<a class="syntax" href="names.html#method-name"><span class="c010">method-name</span></a> of the object denoted by <a class="syntax" href="#expr"><span class="c010">expr</span></a>.</p><p>If <a class="syntax" href="names.html#method-name"><span class="c010">method-name</span></a> is a polymorphic method, its type should be known at
the invocation site. This is true for instance if <a class="syntax" href="#expr"><span class="c010">expr</span></a> is the name
of a fresh object (<span class="c004">let</span> <a class="syntax" href="lex.html#ident"><span class="c010">ident</span></a> = <span class="c004">new</span> &#XA0;<a class="syntax" href="names.html#class-path"><span class="c010">class-path</span></a> &#X2026; ) or if
there is a type constraint. Principality of the derivation can be
checked in the <span class="c003">-principal</span> mode.</p><h4 class="subsubsection" id="sec156">Accessing and modifying instance variables</h4>
<p>The instance variables of a class are visible only in the body of the
methods defined in the same class or a class that inherits from the
class defining the instance variables. The expression <a class="syntax" href="names.html#inst-var-name"><span class="c010">inst-var-name</span></a>
evaluates to the value of the given instance variable. The expression
<a class="syntax" href="names.html#inst-var-name"><span class="c010">inst-var-name</span></a> <span class="c004">&lt;-</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a> assigns the value of <a class="syntax" href="#expr"><span class="c010">expr</span></a> to the instance
variable <a class="syntax" href="names.html#inst-var-name"><span class="c010">inst-var-name</span></a>, which must be mutable. The whole expression
<a class="syntax" href="names.html#inst-var-name"><span class="c010">inst-var-name</span></a> <span class="c004">&lt;-</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a> evaluates to <span class="c004">()</span>.</p><h4 class="subsubsection" id="sec157">Object duplication</h4>
<p>An object can be duplicated using the library function <span class="c003">Oo.copy</span>
(see
<a href="libref/Oo.html">Module <span class="c003">Oo</span></a>). Inside a method, the expression
 <span class="c004">{&lt;</span> <a class="syntax" href="names.html#inst-var-name"><span class="c010">inst-var-name</span></a> <span class="c004">=</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a> &#XA0;{ <span class="c004">;</span> <a class="syntax" href="names.html#inst-var-name"><span class="c010">inst-var-name</span></a> <span class="c004">=</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a> } <span class="c004">&gt;}</span>
returns a copy of self with the given instance variables replaced by
the values of the associated expressions; other instance variables
have the same value in the returned object as in self.</p>
<h3 class="subsection" id="sec158">7.7.6&#XA0;&#XA0;Coercions</h3>
<p> <a id="s:coercions"></a></p><p>Expressions whose type contains object or polymorphic variant types
can be explicitly coerced (weakened) to a supertype.
The expression <span class="c004">(</span><a class="syntax" href="#expr"><span class="c010">expr</span></a> <span class="c004">:&gt;</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a><span class="c004">)</span> coerces the expression <a class="syntax" href="#expr"><span class="c010">expr</span></a>
to type <a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a>.
The expression <span class="c004">(</span><a class="syntax" href="#expr"><span class="c010">expr</span></a> <span class="c004">:</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a><sub>1</sub> <span class="c004">:&gt;</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a><sub>2</sub><span class="c004">)</span> coerces the
expression <a class="syntax" href="#expr"><span class="c010">expr</span></a> from type <a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a><sub>1</sub> to type <a class="syntax" href="types.html#typexpr"><span class="c010">typexpr</span></a><sub>2</sub>.</p><p>The former operator will sometimes fail to coerce an expression <a class="syntax" href="#expr"><span class="c010">expr</span></a>
from a type <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>1</sub> to a type <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>2</sub>
even if type <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>1</sub> is a subtype of type
<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>2</sub>: in the current implementation it only expands two levels of
type abbreviations containing objects and/or polymorphic variants,
keeping only recursion when it is explicit in the class type (for objects).
As an exception to the above algorithm, if both the inferred type of <a class="syntax" href="#expr"><span class="c010">expr</span></a>
and <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a> are ground (<em>i.e.</em> do not contain type variables), the
former operator behaves as the latter one, taking the inferred type of
<a class="syntax" href="#expr"><span class="c010">expr</span></a> as <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>1</sub>. In case of failure with the former operator,
the latter one should be used.</p><p>It is only possible to coerce an expression <a class="syntax" href="#expr"><span class="c010">expr</span></a> from type
<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>1</sub> to type <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>2</sub>, if the type of <a class="syntax" href="#expr"><span class="c010">expr</span></a> is an instance of
<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>1</sub> (like for a type annotation), and <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>1</sub> is a subtype
of <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>2</sub>. The type of the coerced expression is an
instance of <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>2</sub>. If the types contain variables,
they may be instantiated by the subtyping algorithm, but this is only
done after determining whether <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>1</sub> is a potential subtype of
<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>2</sub>. This means that typing may fail during this latter
unification step, even if some instance of <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>1</sub> is a subtype of
some instance of <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>2</sub>.
In the following paragraphs we describe the subtyping relation used.</p><h4 class="subsubsection" id="sec159">Object types</h4>
<p>A fixed object type admits as subtype any object type that includes all
its methods. The types of the methods shall be subtypes of those in
the supertype. Namely,
</p><div class="center">
 <span class="c004">&lt;</span> <a class="syntax" href="names.html#method-name"><span class="c010">met</span></a><sub>1</sub> <span class="c004">:</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>1</sub> <span class="c004">;</span> &#X2026; <span class="c004">;</span> &#XA0;<a class="syntax" href="names.html#method-name"><span class="c010">met</span></a><sub><span class="c009">n</span></sub> <span class="c004">:</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub><span class="c009">n</span></sub> <span class="c004">&gt;</span> 
</div><p>
is a supertype of
</p><div class="center">
 <span class="c004">&lt;</span> <a class="syntax" href="names.html#method-name"><span class="c010">met</span></a><sub>1</sub> <span class="c004">:</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;<sub>1</sub> <span class="c004">;</span> &#X2026; <span class="c004">;</span> <a class="syntax" href="names.html#method-name"><span class="c010">met</span></a><sub><span class="c009">n</span></sub> <span class="c004">:</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;<sub><span class="c009">n</span></sub> <span class="c004">;</span>
<a class="syntax" href="names.html#method-name"><span class="c010">met</span></a><sub><span class="c009">n</span>+1</sub> <span class="c004">:</span> <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;<sub><span class="c009">n</span>+1</sub> <span class="c004">;</span> &#X2026; <span class="c004">;</span> <a class="syntax" href="names.html#method-name"><span class="c010">met</span></a><sub><span class="c009">n</span>+<span class="c009">m</span></sub> <span class="c004">:</span> <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;<sub><span class="c009">n</span>+<span class="c009">m</span></sub>
&#XA0;[<span class="c002"><span class="c003">;</span> <span class="c003">..</span></span>] <span class="c004">&gt;</span> 
</div><p>
which may contain an ellipsis <span class="c003">..</span> if every <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub><span class="c009">i</span></sub> is a supertype of
the corresponding <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;<sub><span class="c009">i</span></sub>.</p><p>A monomorphic method type can be a supertype of a polymorphic method
type. Namely, if <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a> is an instance of <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;, then  <span class="c004">'</span><span class="c010">a</span><sub>1</sub>
&#X2026; <span class="c004">'</span><span class="c010">a</span><sub><span class="c009">n</span></sub> <span class="c004">.</span> <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032; is a subtype of <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>.</p><p>Inside a class definition, newly defined types are not available for
subtyping, as the type abbreviations are not yet completely
defined. There is an exception for coercing <span class="c010">self</span> to the (exact)
type of its class: this is allowed if the type of <span class="c010">self</span> does not
appear in a contravariant position in the class type, <em>i.e.</em> if
there are no binary methods.</p><h4 class="subsubsection" id="sec160">Polymorphic variant types</h4>
<p>A polymorphic variant type <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a> is a subtype of another polymorphic
variant type <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032; if the upper bound of <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a> (<em>i.e.</em> the
maximum set of constructors that may appear in an instance of <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>)
is included in the lower bound of <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;, and the types of arguments
for the constructors of <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a> are subtypes of those in
<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;. Namely,
</p><div class="center">
 <span class="c004">[</span>[<span class="c004">&lt;</span>] <span class="c004">`</span><a class="syntax" href="names.html#constr-name"><span class="c010">C</span></a><sub>1</sub> <span class="c004">of</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>1</sub> <span class="c004">|</span> &#X2026; <span class="c002"><span class="c003">|</span> <span class="c003">`</span></span>&#XA0;<a class="syntax" href="names.html#constr-name"><span class="c010">C</span></a><sub><span class="c009">n</span></sub> <span class="c004">of</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub><span class="c009">n</span></sub> <span class="c004">]</span> 
</div><p>
which may be a shrinkable type, is a subtype of
</p><div class="center">
 <span class="c004">[</span>[<span class="c004">&gt;</span>] <span class="c004">`</span><a class="syntax" href="names.html#constr-name"><span class="c010">C</span></a><sub>1</sub> <span class="c004">of</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;<sub>1</sub> <span class="c004">|</span> &#X2026; <span class="c002"><span class="c003">|</span> <span class="c003">`</span></span><a class="syntax" href="names.html#constr-name"><span class="c010">C</span></a><sub><span class="c009">n</span></sub> <span class="c004">of</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;<sub><span class="c009">n</span></sub>
<span class="c002"><span class="c003">|</span> <span class="c003">`</span></span><a class="syntax" href="names.html#constr-name"><span class="c010">C</span></a><sub><span class="c009">n</span>+1</sub> <span class="c004">of</span> <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;<sub><span class="c009">n</span>+1</sub> <span class="c004">|</span> &#X2026; <span class="c002"><span class="c003">|</span> <span class="c003">`</span></span><a class="syntax" href="names.html#constr-name"><span class="c010">C</span></a><sub><span class="c009">n</span>+<span class="c009">m</span></sub> <span class="c004">of</span>
<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;<sub><span class="c009">n</span>+<span class="c009">m</span></sub> <span class="c004">]</span> 
</div><p>
which may be an extensible type, if every <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub><span class="c009">i</span></sub> is a subtype of <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;<sub><span class="c009">i</span></sub>.</p><h4 class="subsubsection" id="sec161">Variance</h4>
<p>Other types do not introduce new subtyping, but they may propagate the
subtyping of their arguments. For instance, <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>1</sub> <span class="c004">*</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>2</sub> is a
subtype of <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;<sub>1</sub> <span class="c004">*</span> <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;<sub>2</sub> when <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>1</sub> and <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>2</sub> are
respectively subtypes of <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;<sub>1</sub> and <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;<sub>2</sub>.
For function types, the relation is more subtle:
<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>1</sub> <span class="c004">-&gt;</span> &#XA0;<a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>2</sub> is a subtype of <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;<sub>1</sub>&#XA0;<span class="c004">-&gt;</span> <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;<sub>2</sub>
if <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>1</sub> is a supertype of <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;<sub>1</sub> and <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a><sub>2</sub> is a
subtype of <a class="syntax" href="types.html#typexpr"><span class="c010">typ</span></a>&#X2032;<sub>2</sub>. For this reason, function types are covariant in
their second argument (like tuples), but contravariant in their first
argument. Mutable types, like <span class="c003">array</span> or <span class="c003">ref</span> are neither covariant
nor contravariant, they are nonvariant, that is they do not propagate
subtyping.</p><p>For user-defined types, the variance is automatically inferred: a
parameter is covariant if it has only covariant occurrences,
contravariant if it has only contravariant occurrences,
variance-free if it has no occurrences, and nonvariant otherwise.
A variance-free parameter may change freely through subtyping, it does
not have to be a subtype or a supertype.
For abstract and private types, the variance must be given explicitly
(see section&#XA0;<a href="typedecl.html#s%3Atype-defs">7.8.1</a>),
otherwise the default is nonvariant. This is also the case for
constrained arguments in type definitions.</p>
<h3 class="subsection" id="sec162">7.7.7&#XA0;&#XA0;Other</h3>
<h4 class="subsubsection" id="sec163">Assertion checking</h4>
<p><a id="hevea_manual.kwd84"></a></p><p>OCaml supports the <span class="c004">assert</span> construct to check debugging assertions.
The expression <span class="c004">assert</span> <a class="syntax" href="#expr"><span class="c010">expr</span></a> evaluates the expression <a class="syntax" href="#expr"><span class="c010">expr</span></a> and
returns <span class="c004">()</span> if <a class="syntax" href="#expr"><span class="c010">expr</span></a> evaluates to <span class="c004">true</span>. If it evaluates to
<span class="c004">false</span> the exception
<span class="c003">Assert_failure</span> is raised with the source file name and the
location of <a class="syntax" href="#expr"><span class="c010">expr</span></a> as arguments. Assertion
checking can be turned off with the <span class="c003">-noassert</span> compiler option. In
this case, <a class="syntax" href="#expr"><span class="c010">expr</span></a> is not evaluated at all.</p><p>As a special case, <span class="c004">assert false</span> is reduced to
<span class="c004">raise</span> <span class="c003"><span class="c002">(</span>Assert_failure ...<span class="c002">)</span></span>, which gives it a polymorphic
type. This means that it can be used in place of any expression (for
example as a branch of any pattern-matching). It also means that
the <span class="c004">assert false</span> &#X201C;assertions&#X201D; cannot be turned off by the
<span class="c003">-noassert</span> option.
<a id="hevea_manual3"></a></p><h4 class="subsubsection" id="sec164">Lazy expressions</h4>
<p>
<a id="hevea_manual.kwd85"></a></p><p>The expression <span class="c004">lazy</span> <a class="syntax" href="#expr"><span class="c010">expr</span></a> returns a value <span class="c009">v</span> of type <span class="c003">Lazy.t</span> that
encapsulates the computation of <a class="syntax" href="#expr"><span class="c010">expr</span></a>. The argument <a class="syntax" href="#expr"><span class="c010">expr</span></a> is not
evaluated at this point in the program. Instead, its evaluation will
be performed the first time the function <span class="c003">Lazy.force</span> is applied to the value
<span class="c009">v</span>, returning the actual value of <a class="syntax" href="#expr"><span class="c010">expr</span></a>. Subsequent applications
of <span class="c003">Lazy.force</span> to <span class="c009">v</span> do not evaluate <a class="syntax" href="#expr"><span class="c010">expr</span></a> again. Applications
of <span class="c003">Lazy.force</span> may be implicit through pattern matching (see&#XA0;<a href="extn.html#s%3Alazypat">8.3</a>).</p><h4 class="subsubsection" id="sec165">Local modules</h4>
<p>
<a id="hevea_manual.kwd86"></a>
<a id="hevea_manual.kwd87"></a></p><p>The expression
<span class="c002"><span class="c003">let</span> <span class="c003">module</span></span> <a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a> <span class="c004">=</span> &#XA0;<a class="syntax" href="modules.html#module-expr"><span class="c010">module-expr</span></a> <span class="c004">in</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a>
locally binds the module expression <a class="syntax" href="modules.html#module-expr"><span class="c010">module-expr</span></a> to the identifier
<a class="syntax" href="names.html#module-name"><span class="c010">module-name</span></a> during the evaluation of the expression <a class="syntax" href="#expr"><span class="c010">expr</span></a>.
It then returns the value of <a class="syntax" href="#expr"><span class="c010">expr</span></a>. For example:
</p><pre>        let remove_duplicates comparison_fun string_list =
          let module StringSet =
            Set.Make(struct type t = string
                            let compare = comparison_fun end) in
          StringSet.elements
            (List.fold_right StringSet.add string_list StringSet.empty)
</pre><h4 class="subsubsection" id="sec166">Local opens</h4>
<p>
<a id="hevea_manual.kwd88"></a>
<a id="hevea_manual.kwd89"></a></p><p>The expressions <span class="c002"><span class="c003">let</span> <span class="c003">open</span></span> <a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a> <span class="c004">in</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a> and
<a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a><span class="c004">.(</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><span class="c004">)</span> are strictly equivalent. These
constructions locally open the module referred to by the module path
<a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a> in the respective scope of the expression <a class="syntax" href="#expr"><span class="c010">expr</span></a>.</p><p>When the body of a local open expression is delimited by
<span class="c002"><span class="c003">[</span> <span class="c003">]</span></span>, <span class="c002"><span class="c003">[|</span> <span class="c003">|]</span></span>, or <span class="c002"><span class="c003">{</span> <span class="c003">}</span></span>, the parentheses can be omitted.
For expression, parentheses can also be omitted for <span class="c002"><span class="c003">{&lt;</span> <span class="c003">&gt;}</span></span>.
For example, <a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a><span class="c004">.[</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><span class="c004">]</span> is equivalent to
<a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a><span class="c004">.([</span>&#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a><span class="c004">])</span>, and <a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a><span class="c004">.[|</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a> <span class="c004">|]</span> is
equivalent to <a class="syntax" href="names.html#module-path"><span class="c010">module-path</span></a><span class="c004">.([|</span> &#XA0;<a class="syntax" href="#expr"><span class="c010">expr</span></a> <span class="c004">|])</span>.</p>
<hr>
<a href="patterns.html"><img src="previous_motif.gif" alt="Previous"></a>
<a href="language.html"><img src="contents_motif.gif" alt="Up"></a>
<a href="typedecl.html"><img src="next_motif.gif" alt="Next"></a>
</body>
</html>
